import audioMgr from "./audioMgr";
import playerDataInfo from "./playerData";

const { ccclass, property } = cc._decorator;

@ccclass
export default class pfSetting extends cc.Component {
    @property(cc.Node)
    node_musicOpen: cc.Node = null;
    @property(cc.Node)
    node_soundOpen: cc.Node = null;

    onLoad() {

    }

    initData() {

    }

    //开启或关闭背景音乐
    onButtonMusicCallback(event) {
        this.node_musicOpen.active = !this.node_musicOpen.active;
        let musicState;
        //@ts-ignore
        if (playerDataInfo.gameData.isMusic == 1) musicState = 0;
        else musicState = 1;

        playerDataInfo.setGameDataByKey("isMusic", musicState);
        if (musicState == 1) {
            audioMgr.playGameAudio("music");
        }
        else {
            audioMgr.stopGameAudio("music");
        }
    }

    //开启或关闭游戏音效
    onButtonSoundCallback() {
        // window.audioMgr.playGameAudio("buttonCheck");
        this.node_soundOpen.active = !this.node_soundOpen.active;

        var soundState;
        //@ts-ignore
        if (playerDataInfo.gameData.isSound == 1) soundState = 0;
        else soundState = 1;

        playerDataInfo.setGameDataByKey("isSound", soundState);
    }

    onButtonCloseCallback() {
        this.node.removeFromParent();
    }
}
